/**
 * 个人发布待审核数据
 */
function adaptUserPublish(item) {
  return {
    id: item.code,
    source: "personal",
    scene: "code",
    status: item.status,
    current: {
      positionName: item.positionName,
      positionDetail: item.positionDetail,
      positionRequire: item.positionRequire,
      lowestSalaryMonth: item.lowestSalaryMonth,
      highestSalaryMonth: item.highestSalaryMonth,
      positionType: item.positionType,
      education: item.education,
      startAt: item.startAt,
      endAt: item.endAt
    },
    userInfo: null,
    failedMessage: item.failedMessage || ""
  };
}

/**
 * 个人发布成功数据
 */
function adaptUserSuccess(item) {
  return {
    id: item.positionId,
    source: "personal",
    scene: "positionId",
    status: item.status,
    current: {
      positionName: item.positionName,
      positionDetail: item.positionDetail,
      positionRequire: item.positionRequire,
      lowestSalaryMonth: item.lowestSalaryMonth,
      highestSalaryMonth: item.highestSalaryMonth,
      positionType: item.positionType,
      education: item.education,
      startAt: item.startAt,
      endAt: item.endAt
    },
    userInfo: null,
    failedMessage: item.failMessage || ""
  };
}

/**
 * 适配公司发布待审核数据
 */
function adaptCompanyPublish(item) {
  return {
    id: item.code,
    source: "company",
    scene: "code",
    status: item.status,
    current: {
      positionName: item.positionName,
      positionDetail: item.positionDetail,
      positionRequire: item.positionRequire,
      lowestSalaryMonth: item.lowestSalaryMonth,
      highestSalaryMonth: item.highestSalaryMonth,
      positionType: item.positionType,
      education: item.education,
      startAt: item.startAt,
      endAt: item.endAt
    },
    userInfo: {
      userId: item.userId,
      avatar: item.avatar,
      name: item.name
    },
    failedMessage: item.failedMessage || ""
  };
}

/**
 * 适配公司发布成功数据
 */
function adaptCompanySuccess(item) {
  return {
    id: item.positionId,
    source: "company",
    scene: "positionId",
    status: item.status,
    current: {
      positionName: item.positionName,
      positionDetail: item.positionDetail,
      positionRequire: item.positionRequire,
      lowestSalaryMonth: item.lowestSalaryMonth,
      highestSalaryMonth: item.highestSalaryMonth,
      positionType: item.positionType,
      education: item.education,
      startAt: item.startAt,
      endAt: item.endAt
    },
    userInfo: {
      userId: item.userId,
      avatar: item.avatar,
      name: item.name
    },
    failedMessage: item.failMessage || ""
  };
}

/**
 * 适配带审核岗位详情数据（根据code获取的待审核岗位）
 */
function adaptPositionDetailByCode(item) {
  return {
    id: item.code,
    source: "personal",
    scene: "code",
    status: item.status,
    current: {
      positionName: item.positionName,
      positionDetail: item.positionDetail,
      positionRequire: item.positionRequire,
      lowestSalaryMonth: item.lowestSalaryMonth,
      highestSalaryMonth: item.highestSalaryMonth,
      positionType: item.positionType,
      education: item.education,
      startAt: item.startAt,
      endAt: item.endAt
    },
    userInfo: {
      userId: item.userId,
      avatar: item.avatar,
      name: item.name
    },
    failedMessage: item.failedMessage || ""
  };
}

/**
 * 适配发布成功岗位详情数据（根据position获取的待审核岗位）
 */
function adaptPositionDetailByPositionId(item) {
  return {
    id: item.positionId,
    source: "personal",
    scene: "positionId",
    status: item.status,
    current: {
      positionName: item.positionName,
      positionDetail: item.positionDetail,
      positionRequire: item.positionRequire,
      lowestSalaryMonth: item.lowestSalaryMonth,
      highestSalaryMonth: item.highestSalaryMonth,
      positionType: item.positionType,
      education: item.education,
      startAt: item.startAt,
      endAt: item.endAt
    },
    userInfo: {
      userId: item.userId,
      avatar: item.avatar,
      name: item.name
    },
    failedMessage: item.failedMessage || ""
  };
}

//变更岗位详情
function UpdatePositionDetailByPositionId(item) {
  return {
    id: item.newJobMessageResp.positionId,
    source: "personal",
    scene: "positionId",
    status: item.status,
    current: {
      positionName: item.newJobMessageResp.positionName,
      positionDetail: item.newJobMessageResp.positionDetail,
      positionRequire: item.newJobMessageResp.positionRequire,
      lowestSalaryMonth: item.newJobMessageResp.lowestSalaryMonth,
      highestSalaryMonth: item.newJobMessageResp.highestSalaryMonth,
      positionType: item.newJobMessageResp.positionType,
      education: item.newJobMessageResp.education,
      startAt: item.newJobMessageResp.startAt,
      endAt: item.newJobMessageResp.endAt
    },
    old: {
      positionName: item.oldJobMessageResp.positionName,
      positionDetail: item.oldJobMessageResp.positionDetail,
      positionRequire: item.oldJobMessageResp.positionRequire,
      lowestSalaryMonth: item.oldJobMessageResp.lowestSalaryMonth,
      highestSalaryMonth: item.oldJobMessageResp.highestSalaryMonth,
      positionType: item.oldJobMessageResp.positionType,
      education: item.oldJobMessageResp.education,
      startAt: item.oldJobMessageResp.startAt,
      endAt: item.oldJobMessageResp.endAt
    },
    userInfo: {
      userId: item.userId,
      avatar: item.avatar,
      name: item.name
    },
    failedMessage: item.failedMessage || ""
  };
}
/**
 * 批量适配接口数据
 * @param {string} apiName - 接口名称
 * @param {Array} rawList - 接口返回的原始数据列表
 * @returns {Array} 标准化后的列表
 */
export function adaptPositionList(apiName, rawList) {
  const adaptMap = {
    getUserPublishPositions: adaptUserPublish,
    getUserPositions: adaptUserSuccess,
    getCompanyPublishPositions: adaptCompanyPublish,
    getCompanyPositions: adaptCompanySuccess,
    getUserPublishPositionByCode: adaptPositionDetailByCode,
    getUserPositionById: adaptPositionDetailByPositionId,
    checkPositionChangeInformation: UpdatePositionDetailByPositionId
  };

  const adaptFunc = adaptMap[apiName];
  if (!adaptFunc) {
    console.error(`未找到${apiName}的适配规则`);
    return [];
  }

  return rawList.map(item => adaptFunc(item));
}